package com.zl.tby.service.impl;

import com.zl.tby.model.TbyUavInfo;
import com.zl.tby.model.TbyUavInfoBackups;
import com.zl.tby.repository.TbyUavInfoBackupsRepo;
import com.zl.tby.service.ITbyUavInfoBackupsService;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;
import org.noear.wood.annotation.Db;

import java.util.List;

/**
 * 无人机信息备份
 * @author AnWeiNan
 * @date 2024年11月05日 下午8:00
 */

@Slf4j
@Component
public class TbyUavInfoBackupsServiceImpl implements ITbyUavInfoBackupsService {

    @Db
    private TbyUavInfoBackupsRepo tbyUavInfoBackupsRepo;

    @Override
    public void addOrUpdate(TbyUavInfoBackups entity) {

        Long id = entity.getId();
        // 通过 ID 从数据库中选择记录
        List<TbyUavInfoBackups> infoList = tbyUavInfoBackupsRepo.selectList(mp -> {
            mp.whereEq("id", id);
        });

        // 判断对象是否为空
        if (infoList.size() > 0) {
            tbyUavInfoBackupsRepo.updateById(entity, true);
        } else {
            tbyUavInfoBackupsRepo.insert(entity, true);
        }
    }
}
